<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta content="telephone=no" name="format-detection" />
    <!-- 留作将来统一添加 -->
    <TEMPLATE>${TEMPLATE}</TEMPLATE>
    <title>模板html</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css">
    <link rel="stylesheet" type="text/css" href="../../css/index.css">
    <link rel="stylesheet" type="text/css" href="../../css/data-flex.min.css">
    <style type="text/css">
        body {
            background: rgba(90, 194, 255, 1);
        }

        .vueApp {
            padding-bottom: 15px;
        }

        .container {
            margin: 15px;
            padding: 0 15px;
            background: rgba(255, 255, 255, 1);
            box-shadow: 0px 4px 10px 0px rgba(0, 135, 214, 0.37);
            border-radius: 10px;
        }

        .row {
            height: 50px;
        }

        .bor {
            height: 1px;
            background: rgb(212, 212, 212);
            transform: translateY(0.5);
        }

        .title {
            font-size: 15px;
            font-weight: 500;
            color: rgba(25, 25, 25, 1);
        }

        .arrow {
            width: 17px;
            height: 16px;
            margin-left: 7px;
        }

        .text {
            text-align: right;
            font-size: 15px;
            font-weight: 400;
            color: rgba(191, 191, 191, 1);
        }

        .btn {
            width: 210px;
            height: 46px;
            background: url("../../image/ui/btn_3.png");
            background-size: 100% 100%;
            margin: 45px auto 0 auto;
            font-size: 18px;
            font-weight: 600;
            color: rgba(255, 255, 255, 1);
            line-height: 42px;
            text-align: center;
            box-shadow: 0px 5px 7px 0px rgba(11, 126, 193, 0.53);
            border-radius: 22px;
        }
    </style>
</head>

<body>
    <div class="vueApp" v-cloak>
        <div class="container">
            <div class="row" data-flex="main:justify cross:center" onclick="fnOpenPublicWin('修改支付密码','teacher/change_pay_pwd')">
                <div class="title">修改支付密码</div>
                <div class="arrow">
                    <img src="../../image/ui/arrow_right_2.png" alt="">
                </div>
            </div>
            <div class="bor"></div>
            <div class="row" data-flex="main:justify cross:center" onclick="fnOpenPublicWin('修改手机号','teacher/change_tel_1')">
                <div class="title">修改手机号</div>
                <div class="arrow">
                    <img src="../../image/ui/arrow_right_2.png" alt="">
                </div>
            </div>
            <div class="bor"></div>
            <div class="row" data-flex="main:justify cross:center" onclick="fnOpenPublicWin('修改登录密码','teacher/change_login_pwd')">
                <div class="title">修改登录密码</div>
                <div class="arrow">
                    <img src="../../image/ui/arrow_right_2.png" alt="">
                </div>
            </div>
            <div class="bor"></div>
            <div class="row" onclick="handleWX()" data-flex="main:justify cross:center">
                <div class="title">绑定微信账户</div>
                <div class="text" data-flex-box="1">{{wecharOpenId.length > 0 ? '已绑定' : '去绑定'}}</div>
                <div class="arrow">
                    <img src="../../image/ui/arrow_right_2.png" alt="">
                </div>
            </div>
        </div>
        <div onclick="handleLogout()" class="btn">退出登录</div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/service/service-tool.js"></script>
<script type="text/javascript" src="../../script/service/service-app.js"></script>
<script type="text/javascript" src="../../script/service/service-user.js"></script>
<script type="text/javascript" src="../../script/service/service-logic.js"></script>
<script type="text/javascript" src="../../script/service/service-login.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript">
    // html 的引号一律为双引号(""),js 为单引号('')
    var USER, $S, vm;
    var wecharOpenId = '', pageParam;
    apiready = function () {
        $S = SERVICE();
        USER = USER();
        console.log(JSON.stringify(api.pageParam) + '=====pageParam');
        pageParam = api.pageParam;
        fnInit();
    };
    // 初始化
    function fnInit() {
        vm = new Vue({
            el: '.vueApp',
            data: {
                wecharOpenId: USER.Get("weixinOpenid", true) || "",
            }
        });
        wecharOpenId = USER.Get("weixinOpenid", true) || "";
        vm.wecharOpenId = wecharOpenId;
    }

    // 绑定微信
    function handleWX() {
        if (vm.wecharOpenId == '') {
            fnLoginType('1', function(_param, ret1, err1) {
                console.log(JSON.stringify(_param));
                console.log(JSON.stringify(ret1))
                console.log(JSON.stringify(err1));
                var _nickName, _photo;
                _nickName = ret1.nickname;
                _photo = ret1.headimgurl;
                fnMobileBind(_param.openId);
            });
        }else {
            fnOpenAlert({
                alertType: 17,
                alertConfirmFn: 'bindWechat(false)'
            });
        }
    }

    function fnMobileBind(_wecharOpenId) {
        wecharOpenId = _wecharOpenId;
        bindWechat(true);
    }

    function handleLogout() {
        fnOpenAlert({
            alertType: '2',
            alertConfirmFn: 'quitLogin'
        })
    }

    function quitLogin() {
        // var phone = USER.Get('phone')+'';
        USER.Clear();
        // USER.Set({'phone': phone});
        // vm.custId = USER.Get("custId", true) || "";
        api.sendEvent({
            name: 'loginStatus',
            extra: {
                login: false,
            }
        });
        api.execScript({
            name: pageParam.winName,
            frameName: pageParam.frameName,
            script: 'quitLogin();'
        });
        
        var param = {
            name: 'login',
            url: '../login/login.html',
            pageParam: {
                closeWinName: api.winName
            }
        }
        fnOpenWin(param);
    }

    // 绑定微信
    function bindWechat(isBind) {
        var params = {
            type: '2',
            weixinOpenid: wecharOpenId
        };
        if(isBind) {
            params.type = '1';
        };
        var url = 'my/bindingWeChat';
        var callback = function(data) {
            if(params.type == 1) {
                vm.wecharOpenId = wecharOpenId;
                USER.Set({weixinOpenid: params.weixinOpenid})
            }else {
                USER.Set({weixinOpenid: ''});
                vm.wecharOpenId = '';
                wecharOpenId = '';
            }
        };
        POST(url, params, callback);
    }
</script>

</html>